﻿//
//  websocketmanager.h
//  websocketserver
//
//  Created by cl.zhan on 17/5/26.
//  email:zhanchonglongba@126.com/690759587
//
//

#ifndef WEBSOCKETMANAGER_H_H_
#define WEBSOCKETMANAGER_H_H_

#include <QtCore>
#include <QtWebSockets>
#include <QList>
#include<QMutex>



class HttpClientConnection;
class LiveManager;

QT_FORWARD_DECLARE_CLASS(QWebSocketServer)
QT_FORWARD_DECLARE_CLASS(QWebSocket)

class WebSocketManager : public QObject
{
    Q_OBJECT
public:
    WebSocketManager();
    ~WebSocketManager();
    int startWebSocket(int port);
    int stopWebSocket();
    int InitLiveManager();

    quint16 serverPort() { return server->serverPort(); }
    QHostAddress get_client_address()
    {
        return client_address;
    }

    int SendRemovePull(QString & url);

signals:
    void closed();


private slots:
    void onAcceptError(QAbstractSocket::SocketError socketError);
    void onServerError(QWebSocketProtocol::CloseCode closeCode);
    void onNewConnection();

    void LivesocketDisconnected();



private:
    QWebSocketServer* server;
    QHostAddress client_address;
    QList<HttpClientConnection*> clients;
    QMutex	cs_live_;
    LiveManager * master_live_manager;

};

#endif
